let number = document.querySelector(".number");
let sel = document.querySelector(".sel");
let option = document.querySelector("option");
let a = sessionStorage.getItem("token");
let status = document.querySelector(".status");
let sta;
let sta1 = document.querySelectorAll(".sta");
let d;
let api = `http://newshopapi.0melon0.cn/api/f_user/chooselist?token=${a}`;
let method = "GET";

ajax(method, api, (data) => {
    console.log(data);
    // console.log(data.result.list);
    data.result.list.forEach((item) => {
        // console.log(item);
        console.log(item.day_time);
        //  d=item.day_time;
        // let e = item.day_time.split("-");
        // sel.innerHTML += `<option >${e[1]}月${e[2]}日</option>`;
        sel.innerHTML += `<option >${item.day_time}</option>`;
    });

    sel.addEventListener("change", function(e) {
        // console.log(e);
        let b = e.target.value;
        sessionStorage.setItem("b", b);

        let api = `http://newshopapi.0melon0.cn/api/f_user/chooseday?token=${a}&day_time=${b}`;
        let method = "GET";

        ajax(method, api, data => {
            console.log(data);
            data.result.list.forEach((item) => {

                let time1 = item.day_time.slice(0, 10); //2021-10-25
                let time2 = item.show_name.slice(0, 5); //09:00
                let time3 = item.show_name.slice(6, 11); //12:00



                let timer1 = new Date(time1 + " " + time2).getTime();
                let timer3 = new Date(time1 + " " + time3).getTime();
                let timer = new Date().getTime() //当前时间


                if (timer1 >= timer && timer3 >= timer) {
                    sta = "可预约";
                    // flag = true;
                } else {
                    sta = "不可预约";
                    // flag = false;
                };


                status.addEventListener("click", e => {
                    // console.log(item.show_id);

                    if (sta === "可预约") {
                        status.addEventListener("click", function(e) {
                            console.log(e);
                            layui.use('layer', function() {
                                var layer = layui.layer;
                                layer.alert('登录成功');

                                setTimeout(function() {
                                    window.location.href = "./success.html"
                                }, 2000)
                            });
                        })
                    } else {
                        alert("不可预约")
                    }
                })



            });

            status.innerHTML = `
            <p >状态</p>
            <p class="sta">${sta}</p>
            <p class="sta">${sta}</p>
            <p class="sta">${sta}</p>
            `;
            console.log(sta);
            if (sta === "不可预约") {
                console.log(sta1);
                status.style.color = "red";
            }
            if (sta === "可预约") {
                status.style.color = "green";
            }

            number.innerHTML = `

            <p>次数</p>
            <p>${data.result.list[0].show_name}</p>
            <p>${data.result.list[1].show_name}</p>
            <p>${data.result.list[2].show_name}</p>
            `;




        })
    })

})